package com.vmladenov.cook.core.adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.vmladenov.cook.R;
import com.vmladenov.cook.core.db.proxy.RecipeComment;

public class RecipeCommentAdaptor extends ArrayAdapter<RecipeComment>
{
	LayoutInflater inflater;

	public RecipeCommentAdaptor(Context context, RecipeComment[] recipeComments)
	{
		super(context, R.layout.recipe_comment_item_view, recipeComments);
		inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent)
	{
		View v = convertView;
		if (v == null)
		{
			v = inflater.inflate(R.layout.recipe_comment_item_view, null);
		}

		RecipeComment comment = getItem(position);
		if (comment != null)
		{
			TextView tvComment = (TextView) v.findViewById(R.id.tvRecipeComment);
			tvComment.setText(comment.Comment);

			TextView tvUserName = (TextView) v.findViewById(R.id.tvUserName);
			tvUserName.setText(comment.UserName);

			TextView tvCommentDate = (TextView) v.findViewById(R.id.tvCommentDate);
			tvCommentDate.setText(comment.CommentDate.toLocaleString());
		}
		return v;
	}

}
